class ProjectMessage < ActiveRecord::Base

  default_scope { where(:deleted_at => nil) }
  default_scope { order(id: :desc) }

  PER_PAGE = 10
  paginates_per PER_PAGE

  has_one :users
  has_one :project
  
  # 虚拟字段
  # 获取发帖人信息
  def post_user
    return User.find(self.user_id)
  end
  # 获取项目
  def post_project
    return Project.find(self.project_id)
  end
  # 留言回复
  def post_reply
    @reply_message = ProjectMessage.where('reply_id' => self.id, isshow: true).first
    if @reply_message.blank?
      return ''
    else
      return @reply_message.message
    end
  end

end
